package com.logos.musicframe.config;

import com.logos.musicframe.adapter.AliStorageAdapter;
import com.logos.musicframe.adapter.MinioStorageAdapter;
import com.logos.musicframe.adapter.StorageAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @author logos
 * date 2025/6/05 12:41
 * @version v1.0
 * @Package com.logos.musicframe.config
 */
@Configuration
@Slf4j
@RefreshScope
public class StorageConfig{

    @Value("${storage.service.type}")
    private String storageType;

    @Bean
    @RefreshScope
    public StorageAdapter storageService() {
        log.info("打印从nacos获取的配置:{}", storageType);
        if ("minio".equals(storageType)) {
            return new MinioStorageAdapter();
        } else if ("aliyun".equals(storageType)) {
            return new AliStorageAdapter();
        } else {
            throw new IllegalArgumentException("未找到对应的文件存储处理器");
        }
    }
}
